package com.yami.shop.rights.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.thoughtworks.xstream.core.SecurityUtils;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.rights.common.dto.RightsRecordDto;
import com.yami.shop.rights.common.service.RightsRecordService;
import com.yami.shop.security.common.util.AuthUserContext;
import com.yami.shop.user.common.dto.UserBalanceLogDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController("rightsRecordController")
@RequestMapping("/dtc/app/rightsRecord")
@Tag(name = "app-权益记录信息")
@AllArgsConstructor
public class RightsRecordController {

    @Autowired
    private RightsRecordService rightsRecordService;

    /**
     * 分页权益核销记录
     * @param page 分页对象 type 1: 使用记录 2: 核销记录
     * @return 分页数据
     */
    @GetMapping("/page" )
    @Operation(summary =  "分页权益核销记录", description = "分页权益核销记录")
    public ServerResponseEntity<IPage<RightsRecordDto>> getUserBalanceLogPage(PageParam<RightsRecordDto> page,String type) {
        if(ObjectUtil.isEmpty(type)){
            throw new YamiShopBindException("查询类型不能为空");
        }
        String userId = AuthUserContext.get().getUserId();
        IPage<RightsRecordDto> rightsRecordDtoIPage = rightsRecordService.getRightsRecord(page, userId,type);
        return ServerResponseEntity.success(rightsRecordDtoIPage);
    }
}
